package tgc.edu.szxt.demo.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import tgc.edu.szxt.demo.entity.SysUser;
import tgc.edu.szxt.demo.security.UserUtils;
import tgc.edu.szxt.demo.service.SysUserService;
import tgc.edu.szxt.demo.web.form.PwdForm;
@Controller
@RequestMapping("/pwd")
public class PwdController {
	
	@Autowired
	UserUtils userUtils;
	@Autowired
	SysUserService sysUserService;
	
	@RequestMapping("/edit")
	public void edit() {
	}
	
	@RequestMapping("/save")
	@ResponseBody
	public Object save(PwdForm pwd) {
		SysUser user = userUtils.getUser();
		BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); 
		String password = encoder.encode(pwd.getPassword2());
		user.setPassword(password);
		sysUserService.save(user);
		return "Ok";
	}
}
